import { http } from '@/utils/http'
export interface IUser {
	id: number
	username: string
	nickname: string
	gender: string
	avatar: string
  cellphone: string
	email: string
	state: string
}

export interface IWXUser {
	openid: string
	session_key: string
	encryptedData: string
	iv: string
}

/** 获取手机号 */
export const getWXPhoneNumber = (code:string) => {
	return http.post(`/auth/wx/cellphone`,{
		grant_type: 'client_credential',
		appid: 'wxdcfd507bc073b2fe', // 小程序的APPID
		secret: '274a27022e85beca24a2fef2028ba800', // 小程序的secret密钥,
		code: code // wx.login 登录成功后的code
	})
}

/** 手机号传给后端登录或注册 */
export const postWXLoginAPI = (cellphone:string) => {
  return http.post('/auth/wx/cellphone/token', {
		cellphone: cellphone
	})
}

/**	用户名密码登录 */
export const postUAPLoginAPI = (username:string, password:string) => {
  return http.post('/auth/token', {
		username,
		password
	})
}

/**	手机号密码登录 */
export const postPAPLoginAPI = (cellphone:string, password:string) => {
  return http.post('/auth/password/token', {
		cellphone,
		password
	})
}

/** 获取当前登录用户信息 */
export const loggedUserInfoAPI = () => {
  return http.get('/users/me')
}

/** 更新基本信息，包括nickname、gender、email、cellphone等 */
export const editUserInfoAPI = (user_id: number, user) => {
	return http.post(`/users/${user_id}`,user)
}